#!/bin/sh
#
# 简单写一下脚本的功能。
#
#
#

if [ $# -lt 1 ]; then
	echo "Usage: $0 words"
	exit
fi

localdir="/Users/hbaolong/workshop/gitee/3place/"

dirs="CNMYDICT 0402八卦 0801道德经 0600论语 0700黄帝内经 0100诗经 0803道德经帛书版 3401文心雕龙 3502桃花扇"

badword=""

okword=""

for arg in "$@"
do
	for newword in `echo $arg |sed -e "s/[，。；“”∶：、《》？]//g"| sed -e "s/./& /g"`
	do

		# 字是否已经出现。

		echo $okword | grep $newword >/dev/null

		if [ $? -eq 0 ]; then

			continue
		fi

		echored [$newword]

		okword=$okword$newword

		iexist=0

		for files in `echo $dirs`
		do
			cd $localdir$files 
			grep "+ "$newword *.md >/dev/null

			if [ $? -eq 0 ]; then 
				let "iexist+=1"
				echogreen "[$files]"
				grep "+ "$newword *.md |awk -Fmd: '{print $2}'|sort |uniq -c |sort -rg |awk -F+ '{print "+"$2}' 
			fi
		done

		if [ $iexist -eq 0 ]; then 

			badword="$badword+$newword"
		fi
	done
done

if [ "$badword" = "" ]; then 
	echored "没有新字词"
else
	echored "请注解一下字词："
	echo $badword |sed -e "s/+/\n+ /g"|sed -e "/^$/d"|sed -e "s/$/，\n/" 
fi
